<?php

namespace app\service;
use think\Request;
use think\facade\Filesystem;
use think\facade\Log;
use app\controller\BaseController;
use app\model\Packages;
use app\model\PackageVersions;
use app\model\Dependencies;

class NestService extends BaseController{
    private $userId;

    public function __construct() {
        $this->userId=1;

    }
    //获取所有版本
    public function getVersions(Request $input){
        $packageName=$input->param('packageName','');
        $packageResult=Packages::getPackagesInfo($packageName);
        $result=PackageVersions::getAllVersions($packageResult->id);
        return $this->return_succ([
            "data"=>[
                "packageName"=>$packageName,
                "versions"=>$result
            ]
        ]);
    }
    //获取元数据
    public function getMetaData(Request $input){
        $packageName=$input->param('packageName','');
        $packageResult=Packages::getPackagesInfo($packageName);
        $result=PackageVersions::getVersionMetaData($packageResult->id);
        $allDependencies=Dependencies::getPackageDependencies($result->id);
        $result->Dependencies=$allDependencies;
        return $this->return_succ([
            "data"=>[
                "packageName"=>$packageName,
                "metadata"=>$result
            ]
        ]);
    }

}
